package com.oocl.rcm.controller.impl;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;

import com.oocl.cmdparse.CmdParser;
import com.oocl.crm.cmdparseipml.CmdParserIpml;
import com.oocl.crm.controller.Controller;
import com.oocl.rcm.model.Customer;
import com.oocl.rcm.util.FormatPrinter;

public class ControllerImpl implements Controller{
	
	private static CmdParserIpml cpi ; 
	private static FormatPrinter fp ;
	
	public ControllerImpl(){
		cpi = new CmdParserIpml();
		fp = new FormatPrinter();
	}

	public void commandProcess(InputStream in, OutputStream out) {
		Scanner sc = new Scanner(in);
		String cmd = sc.nextLine();
	
		switch (cmd.split(" ")[0]) {
		
		case "L":
			Customer[] cs = cpi.find(cmd);
			if(cs!=null){
				fp.printCustomer(cs);
			}else{
				fp.printNotResult();
			}
			break;
		case "A":
			cpi.processAdd(cmd);
			break;
		case "D":
			cpi.processDelete(cmd);
			break;
		case "O":
			Customer[] css = cpi.processSort(cmd);
			fp.printCustomer(css);
			break;
		case "U":
			cpi.processUpdate(cmd);
			break;
		case "H":
			fp.printHelp();
			break;
		case "Q":
			System.exit(0);
			break;
		default:
			fp.cmdError();
		}
	}
	
}
